package com.wenlin.myproduction.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.cahill.roundbanner.BannerAdapter;
import com.cahill.roundbanner.BannerViewHolder;
import com.cahill.roundbanner.MyBannerViewHolder;
import com.cahill.roundbanner.MyCardBanner;
import com.wenlin.myproduction.R;
import com.wenlin.myproduction.base.BaseActivity;
import com.wenlin.myproduction.base.BaseSwipeActivity;
import com.wenlin.myproduction.util.ToastUtils;
import com.wenlin.myproduction.util.ValCommon;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class RoundBannerActivity extends BaseSwipeActivity {
    @BindView(R.id.banner)
    MyCardBanner banner;

    @Override
    public int getContentView() {
        return R.layout.activity_round_banner;
    }

    public static void start(BaseActivity activity) {
        Intent intent = new Intent(activity, RoundBannerActivity.class);
        activity.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitle(ValCommon.ROUND_BANNER);
        setData();
    }

    private void setData() {
        //获取数据，这里设置模拟数据
        List<String> listPictures = new ArrayList<>();
        List<String> listLinks = new ArrayList<>();
        //编造模拟数据
        listPictures.add("https://tcs.teambition.net/thumbnail/3124d719c90c5ac8c8d0b6dd346baabc640c/w/20000/h/20000");
        listLinks.add("https://www.baidu.com");
        listPictures.add("https://tcs.teambition.net/thumbnail/3122c489cd05f43fd31737834a8b5407df70/w/20000/h/20000");
        listLinks.add("https://www.baidu.com");
        listPictures.add("https://tcs.teambition.net/thumbnail/312238f4234e97973d0781b8232a06a252b1/w/20000/h/20000");
        listLinks.add("https://www.baidu.com");
        listPictures.add("https://tcs.teambition.net/thumbnail/31240b2f1d2e5eb24202bdce890f3c6649e9/w/20000/h/20000");
        listLinks.add("https://www.baidu.com");
        //装填数据
        banner.setDataCount(listPictures.size())
                .setBannerAdapter(new BannerAdapter() {
                    @Override
                    public BannerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
                        return new MyBannerViewHolder(LayoutInflater.from(RoundBannerActivity.this)
                                .inflate(R.layout.common_item_banner, parent, false));
                    }

                    @Override
                    public void onBindViewHolder(BannerViewHolder holder, int position) {
                        if (RoundBannerActivity.this.isFinishing()) return;
                        MyBannerViewHolder viewHolder = (MyBannerViewHolder) holder;
                        String pic = listPictures.get(position);
                        Glide.with(RoundBannerActivity.this)
                                .load(pic)
                                .centerCrop()
                                .diskCacheStrategy(DiskCacheStrategy.ALL)
//                    .bitmapTransform(new CropCircleTransformation(getContext()))
                                .into(viewHolder.riv);
                        viewHolder.riv.setOnLongClickListener(view -> {
                            ToastUtils.getInstance().showInfo("查看大图" + pic);
                            //todo 长按轮播图片跳转到查看大图页面，看具体业务需要不需要，不需要的话可以删掉。
                            return true;
                        });
                        viewHolder.riv.setOnClickListener((view -> {
                            String link = listLinks.get(position);
                            ToastUtils.getInstance().showInfo("跳转网页");
                            //todo 点击轮播图片跳转到网页。
                        }));
                    }
                });
        //开始轮播
        banner.start();
    }
}
